#include "CollectableManager.h"
#include "ICollidable.h"
#include "Collectable.h"
#include "ConfigManager.h"
#include "MyWood.h"
#include "MyRock.h"
#include "Sugar.h"
#include "Oil.h"

namespace PeanutQuest {

	CollectableManager::CollectableManager(std::string id) : cg::Entity(id) {
	}
	CollectableManager::~CollectableManager() {
	}

	void CollectableManager::init() {

		config = (ConfigManager*)cg::Registry::instance()->get("ConfigManager");

		collectables.push_back(new MyWood(cg::Vector3f(config->wood1)));
		collectables.push_back(new MyWood(cg::Vector3f(config->wood2)));
		collectables.push_back(new MyWood(cg::Vector3f(config->wood3)));
		collectables.push_back(new MyWood(cg::Vector3f(config->wood4)));
		collectables.push_back(new MyWood(cg::Vector3f(config->wood5)));
		collectables.push_back(new MyWood(cg::Vector3f(config->wood6)));

		collectables.push_back(new MyRock(cg::Vector3f(config->rock1)));
		collectables.push_back(new MyRock(cg::Vector3f(config->rock2)));
		collectables.push_back(new MyRock(cg::Vector3f(config->rock3)));
		collectables.push_back(new MyRock(cg::Vector3f(config->rock4)));

		if(cg::Registry::instance()->exists("Enemy1Manager")) {
			collectables.push_back(new Sugar(cg::Vector3f(config->specialSugar))); 
		}

		if(cg::Registry::instance()->exists("Enemy2Manager")) {
			collectables.push_back(new Sugar(cg::Vector3f(config->specialSugar))); 
			collectables.push_back(new Oil(cg::Vector3f(config->specialOil))); 
		}
	}

	void CollectableManager::update(unsigned long elapsed_millis) {

		for(std::vector<Collectable*>::iterator it = collectables.begin(); it != collectables.end(); ++it){
			(*it)->update(elapsed_millis);
		}

	}

	void CollectableManager::draw() {

		for(std::vector<Collectable*>::iterator it = collectables.begin(); it != collectables.end(); ++it){
			(*it)->draw();
		}

	}

	void CollectableManager::deleteCollectable(Collectable* collectable) {
		collectables.erase(std::remove(collectables.begin(), collectables.end(), collectable), collectables.end());
	}

}